﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPNETVN.PORTAL.Components.UI.DataTypes
{
    public abstract class BaseDataType
    {
        protected int _ControlWidth = 300;
        protected object _InnerDataSource;
        protected Control _InnerControl;
        protected PropertyDataType _InnerDataType;
        protected string _InnerValue = string.Empty;

        /// <summary>
        /// EditControl
        /// </summary>
        public virtual Control EditControl
        {
            get
            {
                if (this._InnerControl == null)
                {
                    //Text box
                    using (TextBox control = new TextBox())
                    {
                        control.CssClass = "TextBox";
                        control.Columns = 30;
                        control.Width = new Unit(this._ControlWidth);
                        control.MaxLength = 1024;
                        this._InnerControl = control;
                    }
                }

                ((TextBox)this._InnerControl).Text = Value;
                return this._InnerControl;
            }
            set
            {
                if (value.GetType().Name == "TextBox")
                {
                    this._InnerControl = value;
                    //Update value from control
                    this.Value = ((TextBox)value).Text;
                }
                else
                    throw new ArgumentException("A TextBox values is required");
            }
        }

        public virtual PropertyDataType DataType
        {
            set { this._InnerDataType = value; }
            get { return this._InnerDataType; }
        }

        public virtual string Value
        {
            get { return (this._InnerValue); }
            set { this._InnerValue = value; }
        }

        public virtual string Description
        {
            get { return string.Empty; }
        }

        public virtual object DataSource
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }
    }
}